package fuxi1;

import java.util.Random;
import java.util.Scanner;

public class TwoArray {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        Random rad=new Random();
        System.out.println("请输入你定义的数组的数");
        int n=sc.nextInt();
        int[][] twoArrays=new int[n][n];
        for (int i=0;i<n;i++){
            for (int j=0;j<n;j++){
                twoArrays[i][j]=rad.nextInt(100)+1;//随机产生1-100之间的数
                System.out.print(twoArrays[i][j]+" ");
            }
            System.out.println();
        }
        int sum=0;
        for (int i=0;i<n;i++){
            for (int j=0;j<n;j++){
                if(i==j){
                    sum+=twoArrays[i][j];
                }
            }
        }
        System.out.println("对角线的和为"+sum);
    }
}
